﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wintellect.PowerCollections;

namespace PriorityQueue
{
    class PriorityQueue<T>:IEnumerable<T>
    {
        private OrderedBag<T> bag;

        public PriorityQueue()
        {
            this.bag = new OrderedBag<T>();
        }

        public void Enqueue(T item)
        {
            this.bag.Add(item);
        }

        public T Dequeue()
        {
            T result = this.bag.RemoveFirst();
            return result;
        }

        public T this[int index]
        {
            get
            {
                if (index > 0 && index < this.bag.Count)
                {
                    return this.bag[index];
                }
                else
                {
                    throw new IndexOutOfRangeException(String.Format("Index {0} is invalid!", index));

                }
            }
           
        }
    
        public IEnumerator<T>  GetEnumerator()
        {
 	       return this.bag.GetEnumerator();
        }

        System.Collections.IEnumerator  System.Collections.IEnumerable.GetEnumerator()
        {
 	        return this.GetEnumerator();
        }
        }
}
